﻿using UnityEngine;
using System.Collections;
using System;
using System.Text;

public class Oc_ModelRotateButton : RecieaveInputObject
{
    CharacterInfoScene charScene;

    Vector3 m_OrizinAngle;

    public override void StartObject()  // start
    {
        m_Cam = GameObject.Find("GameObject/Main Camera").camera;
        charScene = CharacterInfoScene.Instance as CharacterInfoScene;
    }

    public override void UpdateTouch()       // 터치 입력 받는 함수. ButtonTouch 외에 다른 작업할경우 오버라이드해서 구현 사용
    {
        if (Input.GetMouseButtonDown(0))
        {
            Ray ray;
            RaycastHit rayHit;

            ray = m_Cam.ScreenPointToRay(Input.mousePosition);

            if (Raycast(ray, out rayHit))
            {
                m_PretouchOBJ = rayHit.collider.gameObject;
            }

            m_SaveTouchDown.Set(Input.mousePosition.x, Input.mousePosition.y);
        }

        if (Input.GetMouseButton(0))
        {
            //Input.mousePosition.x - m_SaveTouchDown.x
            if (m_PretouchOBJ == gameObject)
            {
                Vector3 ro = charScene.m_3DModel.transform.localRotation.eulerAngles;
                ro.y = m_SaveTouchDown.x - Input.mousePosition.x;
                charScene.m_3DModel.transform.localRotation = Quaternion.Euler(ro);
            }
        }

        if (Input.GetMouseButtonUp(0))
        {         
            m_PretouchOBJ = null;
        }
    }

    public override void UpdateObject()
    {
        if (transform.rotation != Quaternion.Euler(Vector3.zero))
            transform.rotation = Quaternion.Euler(Vector3.zero);    
    }

    //void OnEnable()
    //{
    //    m_OrizinAngle = charScene.m_3DModel.transform.localRotation.eulerAngles;
    //}

    //void OnDisable()
    //{
    //    charScene.m_3DModel.transform.localRotation = Quaternion.Euler(m_OrizinAngle);
    //}
}
